import { Modal } from 'antd';
import { queryDictData, queryPerson } from '@/utils/common';
import AdSelect from '@/components/AdSelect';
import AdSearch from '@/components/AdSearch';
import prompt from '@/components/Prompt';

export const formate = 'YYYY-MM-DD HH:mm:ss';
export const formateNOSecond = 'YYYY-MM-DD HH:mm';
const { confirm } = Modal;

export const codes = {
  page: 'TRAILUPDATEPAGE',
  select: 'TRAILUPDATEPAGE_SELECT',
  showDetail: 'TRAILUPDATEPAGE_VIEW',
  add: 'TRAILUPDATEPAGE_SAVE',
  save: 'TRAILUPDATEPAGE_SAVE',
  remove: 'TRAILUPDATEPAGE_DEL',
  import: 'TRAILUPDATEPAGE_IMPORT',
};
// UNSEALED 草稿、 SUBMITTED 已提交、 CONFIRM 已确认
export const archivesStatusList = [
  { code: 'UNSEALED', value: '草稿' },
  { code: 'CONFIRM', value: '已确认' },
  { code: 'SUBMITTED', value: '已提交' },
];
//轨迹状态
export const statusTrailList = [
  { code: 'SUBMIT', value: '已提交' },
  { code: 'PROCESS', value: '进行中' },
  { code: 'FINISHED', value: '已完成' },
  { code: 'EXCEPTION', value: '异常' },
  { code: 'NOT', value: '查询不到' },
  { code: '', value: '异常' },
];
// 车次类型
export const trainType = [
  { code: 'NORMAL', value: '正常运输' },
  { code: 'EMPTY', value: '放空' },
];

//节点类型
export const trailType = [
  { code: '全程', value: '全程' },
  { code: '配送', value: '配送' },
  { code: '提货', value: '提货' },
  { code: '干线', value: '干线' },
  { code: '系统默认', value: '系统默认' },
];
//节点状态
export const trailNodeStatus = [
  { code: '到达提货', value: '到达提货' },
  { code: '发车确认', value: '发车确认' },
  { code: '到达目的', value: '到达目的' },
  { code: '签收确认', value: '签收确认' },
  { code: '创建订单', value: '创建订单' },
  { code: '其他', value: '其他' },
];

//轨迹更新状态、类型匹配;(一个code对应两个中文)
export const statusAndType = [
  { code: 'ORDER_CREATE', status: '创建订单', type: '系统默认' },
  { code: 'QC_CONFIRM', status: '到达提货', type: '全程' },
  { code: 'QC_SHIP', status: '发车确认', type: '全程' },
  { code: 'QC_ARRIVE', status: '到达目的', type: '全程' },
  { code: 'QC_SIGN', status: '签收确认', type: '全程' },

  { code: 'PS_CONFIRM', status: '到达提货', type: '配送' },
  { code: 'ORDER_SHIP', status: '发车确认', type: '配送' },
  { code: 'ORDER_ARRIVE', status: '到达目的', type: '配送' },
  { code: 'ORDER_SIGN', status: '签收确认', type: '配送' },

  { code: 'OTHER', status: '其他', type: '系统默认' },

  { code: 'TH_CONFIRM', status: '到达提货', type: '提货' },
  { code: 'TH_SHIP', status: '发车确认', type: '提货' },
  { code: 'TH_ARRIVE', status: '到达目的', type: '提货' },
  { code: 'TH_SIGN', status: '签收确认', type: '提货' },

  { code: 'GX_CONFIRM', status: '到达提货', type: '干线' },
  { code: 'GX_SHIP', status: '发车确认', type: '干线' },
  { code: 'GX_ARRIVE', status: '到达目的', type: '干线' },
  { code: 'GX_SIGN', status: '签收确认', type: '干线' },
];
export function formatStatusAndType(list, type, status) {
  let code = '';
  list &&
    list.map(v => {
      if (v.type == type && v.status == status) {
        code = v.code;
        return;
      }
    });
  console.log('type, status', type, status, 'code:', code);
  return code;
}

export const allUrl = {
  userList: 'tms/tms-bill/selectUserList_s',
  userDetail: 'mds/mds-user/viewDetails',
};

export const routeUrl = {
  add: '/carAccount/ArchivesList/addArchives',
};

export const allDispatchType = {
  list: 'trail/trailUpdateList',
  save: 'trail/opreateTrack',
  remove: 'trail/removeArchives',
  operate: 'trail/archivesOperate',
  value: 'trail/allValus',
  selectFileList: 'trail/selectFileList',
  selectEvents: 'trail/selectEvents',
};

export function renderTableAdSelect({
  key,
  data,
  value,
  props,
  type,
  show = { id: 'code', name: 'value' },
}) {
  let params = { onlyRead: true, value };
  if (key) {
    const { dictObject } = props;
    params = { data: dictObject[key], payload: { code: [key] }, ...params };
  } else {
    params = { data, ...params };
  }
  //   let show = { id: 'code', name: 'value' };
  if (type == 'train') {
    show = { id: 'id', name: 'trainNo' };
  }
  params.show = show;
  return <AdSelect {...params} />;
}

export function renderTableAdSearch({ value, props }) {
  if (!value || !searchValue) return '';
  const { searchValue } = props;
  const params = {
    onlyRead: true,
    value: searchValue[value],
    label: 'loginName',
    name: 'sysName',
  };
  return <AdSearch {...params} />;
}

export function selectArchivesList({ payload = {}, props } = {}) {
  const { dispatch, searchValue } = props;
  dispatch({
    type: allDispatchType.list,
    payload,
    callback: data => {
      if (!data) return;
      // queryPerson({ data, props: props, url: allUrl.userList });
    },
  });
}

export function selectArchivesDetailAndInfo({ type, payload, props, callback }) {
  const { dispatch } = props;
  dispatch({
    type,
    payload,
    callback: data => {
      if (!data) return;
      callback && callback(data);
    },
  });
}

export function saveAllValues({ payload = {}, props } = {}) {
  const { dispatch } = props;
  dispatch({
    type: 'trail/allValus',
    payload,
  });
}
